<template>
	<u-popup :show="showfalg" mode="right" @open="open">
		<u-navbar title="发票开取" @leftClick="back" :autoBack="false"></u-navbar>

		<formz ref="formz" :inputs="inputs" :data="data"></formz>
		<fixedbtn>
			<view class="fixedbtnbox">
				<u-button type="primary" @click="updata" :loading="loading">
					{{$z.$t("开取发票")}}
				</u-button>
			</view>
		</fixedbtn>
		<zmodal ref="zmodal"></zmodal>
	</u-popup>
</template>

<script>
	export default {
		components: {
			// zswitch
		},
		data() {
			return {
				b_auto: 0,
				showfalg: false,
				data: {},
				loading: false,
				type: 1,
				activeddh: [],
				inputs: [{
						value: "type",
						label: this.$z.$t("抬头类型"),
						type: "select",
						defaultValue: "0",
						option: [{
								value: "0",
								label: this.$z.$t("个人"),
							},
							{
								value: "1",
								label: this.$z.$t("公司"),
							},
						],
						rule: [{
							required: true,
							message: this.$z.$t("请选择抬头类型"),
							trigger: "blur",
						}, ],
					},

					{
						value: "tk",
						label: this.$z.$t("发票抬头"),
						rule: [{
							required: true,
							message: this.$z.$t("请填写发票抬头"),
							trigger: "blur",
						}, ],
					},
					{
						value: "sh",
						label: this.$z.$t("税号"),
						if: {
							zhi: [{
								value: "type",
								zhi: ["1"],
							}, ],
						},
						rule: [{
							required: true,
							message: this.$z.$t("请填写税号"),
							trigger: "blur",
						}, ],
					},
					{
						value: "khyh",
						label: this.$z.$t("开户银行"),
						if: {
							zhi: [{
								value: "type",
								zhi: ["1"],
							}, ],
						},
						rule: [{
							required: true,
							message: this.$z.$t("请填写开户银行"),
							trigger: "blur",
						}, ],
					},
					{
						value: "yhzh",
						label: this.$z.$t("银行账号"),
						if: {
							zhi: [{
								value: "type",
								zhi: ["1"],
							}, ],
						},
						rule: [{
							required: true,
							message: this.$z.$t("请填写银行账号"),
							trigger: "blur",
						}, ],
					},
					{
						value: "qydz",
						label: this.$z.$t("企业地址"),
						if: {
							zhi: [{
								value: "type",
								zhi: ["1"],
							}, ],
						},
						rule: [{
							required: true,
							message: this.$z.$t("请填写企业地址"),
							trigger: "blur",
						}, ],
					},
					{
						value: "qydh",
						label: this.$z.$t("企业电话"),
						if: {
							zhi: [{
								value: "type",
								zhi: ["1"],
							}, ],
						},
						rule: [{
							required: true,
							message: this.$z.$t("请填写企业电话"),
							trigger: "blur",
						}, ],
					},
				],
			};
		},
		methods: {
			back() {
				this.showfalg = false;
			},
			async show(data, type) {
				console.log('type', type);
				this.type = type
				this.activeddh = data;
				this.showfalg = true;
			},
			async open() {
				// this.$nextTick(() => {
				// 	this.$refs.formz.init();
				// });
			},
			async switchtap() {
				let LlfAgentAuto = await this.$z.request("/LlfAgentAuto", {
					b_auto: this.b_auto,
				});
				console.log(123456, LlfAgentAuto);
			},
			async updata() {
				// this.loading = true
				let data = await this.$refs.formz.validate();
				let jez = 0;
				data.ddhsum = this.activeddh.length;
				this.activeddh.forEach((e, i) => {
					data[`ddh${i + 1}`] = e.ddh;
					jez = jez.add(e.je);
				});
				data.je = jez;
				data.fptype = this.type
				this.loading = true;
				let par = await this.$z.request("/FPcdadd", data);
				console.log(par);
				if (par[0].par == "succeed") {
					this.$refs.zmodal.init({
						content: this.$z.$t("操作成功"),
						confirm: function(res) {
							uni.$z.back();
						},
					});
				} else if (par[0].par == "err_nodata") {
					this.$u.toast(this.$z.$t("金额异常"));
				}
				this.loading = false;
				console.log(data, this.activeddh);
			},
		},
	};
</script>

<style>
	.fixedbtnbox {
		width: 100%;
		padding: 0 30rpx;
	}
</style>